/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.etsmtl.log540.tp3;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author SDION
 */
public class IOUtil {
    public static void close(Object closeableObject) throws IOException {
        if (closeableObject == null) {
            return;
        } else if (closeableObject.getClass() == Socket.class) {
            try {
                ((Socket) closeableObject).close();
            } catch (IOException e) {
                e.printStackTrace();
                throw (e);
            }
        } else if (closeableObject.getClass() == ServerSocket.class) {
            try {
                ((ServerSocket) closeableObject).close();
            } catch (IOException e) {
                e.printStackTrace();
                throw (e);
            }
        } else if (closeableObject.getClass() == InputStream.class) {
            try {
                ((InputStream) closeableObject).close();
            } catch (IOException e) {
                e.printStackTrace();
                throw (e);
            }
        } else if (closeableObject.getClass() == OutputStream.class) {
            try {
                ((OutputStream) closeableObject).close();
            } catch (IOException e) {
                e.printStackTrace();
                throw (e);
            }
        } else if (closeableObject.getClass() == Reader.class) {
            try {
                ((Reader) closeableObject).close();
            } catch (IOException e) {
                e.printStackTrace();
                throw (e);
            }
        } else if (closeableObject.getClass() == Writer.class) {
            try {
                ((Writer) closeableObject).close();
            } catch (IOException e) {
                e.printStackTrace();
                throw (e);
            }
        }

    }
}
